package com.logistics.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.tools.JavaCompiler;

public class Inoutstorefilter implements javax.servlet.Filter{

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain arg2) throws IOException, ServletException {
		// TODO Auto-generated method stub
		HttpServletRequest request=(HttpServletRequest) arg0;
		String requrl= request.getRequestURI();
		if(requrl.equals("/Logistics/login.jsp")||requrl.equals("/Logistics/servlet/Logincheckservlet"))
		{
			arg2.doFilter(request, arg1);
		}
		else {
			HttpSession session=request.getSession();
			int authority = (Integer)session.getAttribute("authority");
			if(authority == 3||authority==6)
			{
				//System.out.println("");
				arg2.doFilter(request, arg1);
			}
			else {
				HttpServletResponse rep=(HttpServletResponse)arg1;
				String urlString=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/login.jsp";
				rep.sendRedirect(urlString);
			}
		}
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
